Work on tasks and idle time properties
authorJeroen van der Heijden <jeroen@transceptor.technology>
Wed, 16 May 2018 14:22:09 +0000 (16:22 +0200)
committerJeroen van der Heijden <jeroen@transceptor.technology>
Wed, 16 May 2018 14:22:09 +0000 (16:22 +0200)
19 files changed:
grammar/gogrammar/grammar.go
grammar/grammar.py
include/siri/db/db.h
include/siri/db/tasks.h [new file with mode: 0644]
include/siri/grammar/grammar.h
include/timeit/timeit.h
src/siri/db/db.c
src/siri/db/initsync.c
src/siri/db/insert.c
src/siri/db/props.c
src/siri/db/query.c
src/siri/db/reindex.c
src/siri/db/replicate.c
src/siri/db/server.c
src/siri/db/shard.c
src/siri/db/tasks.c [new file with mode: 0644]
src/siri/grammar/grammar.c
src/test/test.c
src/timeit/timeit.c

index 89053c28cf7767e4702a16443dd4a314b550b708..b9e12cff145b406b19981b2299376bf52aa18bbf 100644 (file)
@@ -4,7 +4,7 @@ package grammar
 // should be used with the goleri module.
 //
 // Source class: SiriGrammar
-// Created at: 2018-03-30 21:57:58
+// Created at: 2018-05-16 16:15:46
 
 import (
        "regexp"
@@ -118,6 +118,7 @@ const (
        GidIntOperator = iota
        GidKAccess = iota
        GidKActiveHandles = iota
+       GidKActiveTasks = iota
        GidKAddress = iota
        GidKAfter = iota
        GidKAll = iota
@@ -157,6 +158,8 @@ const (
        GidKGroup = iota
        GidKGroups = iota
        GidKHelp = iota
+       GidKIdlePercentage = iota
+       GidKIdleTime = iota
        GidKIgnoreThreshold = iota
        GidKInfo = iota
        GidKInsert = iota
@@ -315,6 +318,7 @@ func SiriGrammar() *goleri.Grammar {
        rComment := goleri.NewRegex(GidRComment, regexp.MustCompile(`^#.*`))
        kAccess := goleri.NewKeyword(GidKAccess, "access", false)
        kActiveHandles := goleri.NewKeyword(GidKActiveHandles, "active_handles", false)
+       kActiveTasks := goleri.NewKeyword(GidKActiveTasks, "active_tasks", false)
        kAddress := goleri.NewKeyword(GidKAddress, "address", false)
        kAfter := goleri.NewKeyword(GidKAfter, "after", false)
        kAll := goleri.NewKeyword(GidKAll, "all", false)
@@ -359,6 +363,8 @@ func SiriGrammar() *goleri.Grammar {
                goleri.NewKeyword(NoGid, "help", false),
                goleri.NewToken(NoGid, "?"),
        )
+       kIdlePercentage := goleri.NewKeyword(GidKIdlePercentage, "idle_percentage", false)
+       kIdleTime := goleri.NewKeyword(GidKIdleTime, "idle_time", false)
        kInfo := goleri.NewKeyword(GidKInfo, "info", false)
        kIgnoreThreshold := goleri.NewKeyword(GidKIgnoreThreshold, "ignore_threshold", false)
        kInsert := goleri.NewKeyword(GidKInsert, "insert", false)
@@ -573,7 +579,10 @@ func SiriGrammar() *goleri.Grammar {
                kStartupTime,
                kStatus,
                kActiveHandles,
+               kActiveTasks,
                kFifoFiles,
+               kIdlePercentage,
+               kIdleTime,
                kLogLevel,
                kMaxOpenFiles,
                kMemUsage,
@@ -757,8 +766,11 @@ func SiriGrammar() *goleri.Grammar {
                                        NoGid,
                                        false,
                                        kActiveHandles,
+                                       kActiveTasks,
                                        kBufferSize,
                                        kFifoFiles,
+                                       kIdlePercentage,
+                                       kIdleTime,
                                        kPort,
                                        kPool,
                                        kStartupTime,
@@ -1573,6 +1585,7 @@ func SiriGrammar() *goleri.Grammar {
                        NoGid,
                        false,
                        kActiveHandles,
+                       kActiveTasks,
                        kBufferPath,
                        kBufferSize,
                        kDbname,
@@ -1581,6 +1594,8 @@ func SiriGrammar() *goleri.Grammar {
                        kDurationLog,
                        kDurationNum,
                        kFifoFiles,
+                       kIdlePercentage,
+                       kIdleTime,
                        kIpSupport,
                        kLibuv,
                        kListLimit,
@@ -1606,123 +1621,123 @@ func SiriGrammar() *goleri.Grammar {
                ), goleri.NewToken(NoGid, ","), 0, 0, false),
        )
        timeitStmt := goleri.NewRepeat(GidTimeitStmt, kTimeit, 1, 1)
-       helpSelect := goleri.NewKeyword(GidHelpSelect, "select", false)
-       helpListGroups := goleri.NewKeyword(GidHelpListGroups, "groups", false)
-       helpListPools := goleri.NewKeyword(GidHelpListPools, "pools", false)
-       helpListShards := goleri.NewKeyword(GidHelpListShards, "shards", false)
-       helpListUsers := goleri.NewKeyword(GidHelpListUsers, "users", false)
-       helpListServers := goleri.NewKeyword(GidHelpListServers, "servers", false)
-       helpListSeries := goleri.NewKeyword(GidHelpListSeries, "series", false)
-       helpList := goleri.NewSequence(
-               GidHelpList,
-               kList,
+       helpAccess := goleri.NewKeyword(GidHelpAccess, "access", false)
+       helpAlterDatabase := goleri.NewKeyword(GidHelpAlterDatabase, "database", false)
+       helpAlterGroup := goleri.NewKeyword(GidHelpAlterGroup, "group", false)
+       helpAlterServer := goleri.NewKeyword(GidHelpAlterServer, "server", false)
+       helpAlterServers := goleri.NewKeyword(GidHelpAlterServers, "servers", false)
+       helpAlterUser := goleri.NewKeyword(GidHelpAlterUser, "user", false)
+       helpAlter := goleri.NewSequence(
+               GidHelpAlter,
+               kAlter,
                goleri.NewOptional(NoGid, goleri.NewChoice(
                        NoGid,
                        true,
-                       helpListGroups,
-                       helpListPools,
-                       helpListShards,
-                       helpListUsers,
-                       helpListServers,
-                       helpListSeries,
+                       helpAlterDatabase,
+                       helpAlterGroup,
+                       helpAlterServer,
+                       helpAlterServers,
+                       helpAlterUser,
                )),
        )
-       helpAccess := goleri.NewKeyword(GidHelpAccess, "access", false)
-       helpRevoke := goleri.NewKeyword(GidHelpRevoke, "revoke", false)
-       helpDropGroup := goleri.NewKeyword(GidHelpDropGroup, "group", false)
-       helpDropSeries := goleri.NewKeyword(GidHelpDropSeries, "series", false)
-       helpDropUser := goleri.NewKeyword(GidHelpDropUser, "user", false)
-       helpDropServer := goleri.NewKeyword(GidHelpDropServer, "server", false)
-       helpDropShards := goleri.NewKeyword(GidHelpDropShards, "shards", false)
-       helpDrop := goleri.NewSequence(
-               GidHelpDrop,
-               kDrop,
+       helpCountGroups := goleri.NewKeyword(GidHelpCountGroups, "groups", false)
+       helpCountPools := goleri.NewKeyword(GidHelpCountPools, "pools", false)
+       helpCountSeries := goleri.NewKeyword(GidHelpCountSeries, "series", false)
+       helpCountServers := goleri.NewKeyword(GidHelpCountServers, "servers", false)
+       helpCountShards := goleri.NewKeyword(GidHelpCountShards, "shards", false)
+       helpCountUsers := goleri.NewKeyword(GidHelpCountUsers, "users", false)
+       helpCount := goleri.NewSequence(
+               GidHelpCount,
+               kCount,
                goleri.NewOptional(NoGid, goleri.NewChoice(
                        NoGid,
                        true,
-                       helpDropGroup,
-                       helpDropSeries,
-                       helpDropUser,
-                       helpDropServer,
-                       helpDropShards,
+                       helpCountGroups,
+                       helpCountPools,
+                       helpCountSeries,
+                       helpCountServers,
+                       helpCountShards,
+                       helpCountUsers,
                )),
        )
-       helpCreateUser := goleri.NewKeyword(GidHelpCreateUser, "user", false)
        helpCreateGroup := goleri.NewKeyword(GidHelpCreateGroup, "group", false)
+       helpCreateUser := goleri.NewKeyword(GidHelpCreateUser, "user", false)
        helpCreate := goleri.NewSequence(
                GidHelpCreate,
                kCreate,
                goleri.NewOptional(NoGid, goleri.NewChoice(
                        NoGid,
                        true,
-                       helpCreateUser,
                        helpCreateGroup,
+                       helpCreateUser,
                )),
        )
-       helpCountGroups := goleri.NewKeyword(GidHelpCountGroups, "groups", false)
-       helpCountPools := goleri.NewKeyword(GidHelpCountPools, "pools", false)
-       helpCountShards := goleri.NewKeyword(GidHelpCountShards, "shards", false)
-       helpCountUsers := goleri.NewKeyword(GidHelpCountUsers, "users", false)
-       helpCountServers := goleri.NewKeyword(GidHelpCountServers, "servers", false)
-       helpCountSeries := goleri.NewKeyword(GidHelpCountSeries, "series", false)
-       helpCount := goleri.NewSequence(
-               GidHelpCount,
-               kCount,
+       helpDropGroup := goleri.NewKeyword(GidHelpDropGroup, "group", false)
+       helpDropSeries := goleri.NewKeyword(GidHelpDropSeries, "series", false)
+       helpDropServer := goleri.NewKeyword(GidHelpDropServer, "server", false)
+       helpDropShards := goleri.NewKeyword(GidHelpDropShards, "shards", false)
+       helpDropUser := goleri.NewKeyword(GidHelpDropUser, "user", false)
+       helpDrop := goleri.NewSequence(
+               GidHelpDrop,
+               kDrop,
                goleri.NewOptional(NoGid, goleri.NewChoice(
                        NoGid,
                        true,
-                       helpCountGroups,
-                       helpCountPools,
-                       helpCountShards,
-                       helpCountUsers,
-                       helpCountServers,
-                       helpCountSeries,
+                       helpDropGroup,
+                       helpDropSeries,
+                       helpDropServer,
+                       helpDropShards,
+                       helpDropUser,
                )),
        )
-       helpNoaccess := goleri.NewKeyword(GidHelpNoaccess, "noaccess", false)
-       helpAlterServer := goleri.NewKeyword(GidHelpAlterServer, "server", false)
-       helpAlterDatabase := goleri.NewKeyword(GidHelpAlterDatabase, "database", false)
-       helpAlterGroup := goleri.NewKeyword(GidHelpAlterGroup, "group", false)
-       helpAlterServers := goleri.NewKeyword(GidHelpAlterServers, "servers", false)
-       helpAlterUser := goleri.NewKeyword(GidHelpAlterUser, "user", false)
-       helpAlter := goleri.NewSequence(
-               GidHelpAlter,
-               kAlter,
+       helpFunctions := goleri.NewKeyword(GidHelpFunctions, "functions", false)
+       helpGrant := goleri.NewKeyword(GidHelpGrant, "grant", false)
+       helpListGroups := goleri.NewKeyword(GidHelpListGroups, "groups", false)
+       helpListPools := goleri.NewKeyword(GidHelpListPools, "pools", false)
+       helpListSeries := goleri.NewKeyword(GidHelpListSeries, "series", false)
+       helpListServers := goleri.NewKeyword(GidHelpListServers, "servers", false)
+       helpListShards := goleri.NewKeyword(GidHelpListShards, "shards", false)
+       helpListUsers := goleri.NewKeyword(GidHelpListUsers, "users", false)
+       helpList := goleri.NewSequence(
+               GidHelpList,
+               kList,
                goleri.NewOptional(NoGid, goleri.NewChoice(
                        NoGid,
                        true,
-                       helpAlterServer,
-                       helpAlterDatabase,
-                       helpAlterGroup,
-                       helpAlterServers,
-                       helpAlterUser,
+                       helpListGroups,
+                       helpListPools,
+                       helpListSeries,
+                       helpListServers,
+                       helpListShards,
+                       helpListUsers,
                )),
        )
+       helpNoaccess := goleri.NewKeyword(GidHelpNoaccess, "noaccess", false)
+       helpRevoke := goleri.NewKeyword(GidHelpRevoke, "revoke", false)
+       helpSelect := goleri.NewKeyword(GidHelpSelect, "select", false)
        helpShow := goleri.NewKeyword(GidHelpShow, "show", false)
-       helpTimezones := goleri.NewKeyword(GidHelpTimezones, "timezones", false)
        helpTimeit := goleri.NewKeyword(GidHelpTimeit, "timeit", false)
-       helpGrant := goleri.NewKeyword(GidHelpGrant, "grant", false)
-       helpFunctions := goleri.NewKeyword(GidHelpFunctions, "functions", false)
+       helpTimezones := goleri.NewKeyword(GidHelpTimezones, "timezones", false)
        help := goleri.NewSequence(
                GidHelp,
                kHelp,
                goleri.NewOptional(NoGid, goleri.NewChoice(
                        NoGid,
                        true,
-                       helpSelect,
-                       helpList,
                        helpAccess,
-                       helpRevoke,
-                       helpDrop,
-                       helpCreate,
+                       helpAlter,
                        helpCount,
+                       helpCreate,
+                       helpDrop,
+                       helpFunctions,
+                       helpGrant,
+                       helpList,
                        helpNoaccess,
-                       helpAlter,
+                       helpRevoke,
+                       helpSelect,
                        helpShow,
-                       helpTimezones,
                        helpTimeit,
-                       helpGrant,
-                       helpFunctions,
+                       helpTimezones,
                )),
        )
        START := goleri.NewSequence(
index 8edc7c3e6fb8da8f41879b9ccf82c06d83c5b2c2..3ac2da6f191c4b7c98d1733e5869fcb88d59016a 100644 (file)
@@ -46,6 +46,7 @@ class SiriGrammar(Grammar):
     # Keywords
     k_access = Keyword('access')
     k_active_handles = Keyword('active_handles')
+    k_active_tasks = Keyword('active_tasks')
     k_address = Keyword('address')
     k_after = Keyword('after')
     k_all = Keyword('all')
@@ -85,6 +86,8 @@ class SiriGrammar(Grammar):
     k_group = Keyword('group')
     k_groups = Keyword('groups')
     k_help = Choice(Keyword('help'), Token('?'))
+    k_idle_percentage = Keyword('idle_percentage')
+    k_idle_time = Keyword('idle_time')
     k_info = Keyword('info')
     k_ignore_threshold = Keyword('ignore_threshold')
     k_insert = Keyword('insert')
@@ -258,7 +261,10 @@ class SiriGrammar(Grammar):
         k_status,
         # Remote properties
         k_active_handles,
+        k_active_tasks,
         k_fifo_files,
+        k_idle_percentage,
+        k_idle_time,
         k_log_level,
         k_max_open_files,
         k_mem_usage,
@@ -333,8 +339,11 @@ class SiriGrammar(Grammar):
     where_server = Sequence(k_where, Prio(
         Sequence(Choice(
             k_active_handles,
+            k_active_tasks,
             k_buffer_size,
             k_fifo_files,
+            k_idle_percentage,
+            k_idle_time,            
             k_port,
             k_pool,
             k_startup_time,
@@ -720,6 +729,7 @@ class SiriGrammar(Grammar):
 
     show_stmt = Sequence(k_show, List(Choice(
         k_active_handles,
+        k_active_tasks,
         k_buffer_path,
         k_buffer_size,
         k_dbname,
@@ -728,6 +738,8 @@ class SiriGrammar(Grammar):
         k_duration_log,
         k_duration_num,
         k_fifo_files,
+        k_idle_percentage,
+        k_idle_time,            
         k_ip_support,
         k_libuv,
         k_list_limit,
index e75a10e192ac3051bb3b5302d33cdd61f311efdb..7f7cc2823d08bef2ac7cfbce598d575777a346c8 100644 (file)
@@ -77,7 +77,6 @@ typedef struct siridb_s
     uint8_t flags;
     uint8_t pad0;
     uint32_t max_series_id;
-    uint16_t active_tasks;
     uint16_t insert_tasks;
     uint16_t shard_mask_num;
     uint16_t shard_mask_log;
@@ -115,8 +114,11 @@ typedef struct siridb_s
     siridb_replicate_t * replicate;
     siridb_reindex_t * reindex;
     siridb_groups_t * groups;
+    siridb_tasks_t tasks;
 } siridb_t;
 
+int32_t siridb_get_uptime(siridb_t * siridb);
+int8_t siridb_get_idle_percentage(siridb_t * siridb);
 int siridb_is_db_path(const char * dbpath);
 siridb_t * siridb_new(const char * dbpath, int lock_flags);
 siridb_t * siridb_get(llist_t * siridb_list, const char * dbname);
diff --git a/include/siri/db/tasks.h b/include/siri/db/tasks.h
new file mode 100644 (file)
index 0000000..a0274a7
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * tasks.h - SiriDB Error.
+ *
+ * author       : Jeroen van der Heijden
+ * email        : jeroen@transceptor.technology
+ * copyright    : 2016, Transceptor Technology
+ *
+ * changes
+ *  - initial version, 31-10-2016
+ *
+ */
+#pragma once
+
+#include <time.h>
+#include <inttypes.h>
+#include <timeit/timeit.h>
+
+typedef struct siridb_tasks_s
+{
+    struct timespec _timeit;
+    uint64_t active;
+    double idle_time;
+} siridb_tasks_t;
+
+
+void siridb_tasks_init(siridb_tasks_t *tasks);
+
+#define siridb_tasks_inc(tasks) \
+if (!tasks.active++) tasks.idle_time += timeit_stop(&tasks._timeit)
+
+#define siridb_tasks_dec(tasks) \
+if (!--tasks.active) timeit_start(&tasks._timeit)
index 2b7471107b34a6556f5d7cd82ffc8411590a5c4a..764dfc2cbc4d69fc75b0c8f26201b1156f00de1f 100644 (file)
@@ -5,7 +5,7 @@
  * should be used with the libcleri module.
  *
  * Source class: SiriGrammar
- * Created at: 2018-03-30 21:57:58
+ * Created at: 2018-05-16 16:15:46
  */
 #ifndef CLERI_EXPORT_SIRI_GRAMMAR_GRAMMAR_H_
 #define CLERI_EXPORT_SIRI_GRAMMAR_GRAMMAR_H_
@@ -118,6 +118,7 @@ enum cleri_grammar_ids {
     CLERI_GID_INT_OPERATOR,
     CLERI_GID_K_ACCESS,
     CLERI_GID_K_ACTIVE_HANDLES,
+    CLERI_GID_K_ACTIVE_TASKS,
     CLERI_GID_K_ADDRESS,
     CLERI_GID_K_AFTER,
     CLERI_GID_K_ALL,
@@ -157,6 +158,8 @@ enum cleri_grammar_ids {
     CLERI_GID_K_GROUP,
     CLERI_GID_K_GROUPS,
     CLERI_GID_K_HELP,
+    CLERI_GID_K_IDLE_PERCENTAGE,
+    CLERI_GID_K_IDLE_TIME,
     CLERI_GID_K_IGNORE_THRESHOLD,
     CLERI_GID_K_INFO,
     CLERI_GID_K_INSERT,
index b8a164e8c458226a78f4b01b1c686fcf5699861e..cc51056a173e212f07df188ff8c27bc46c890f25 100644 (file)
  */
 #pragma once
 
-#include <sys/time.h>
-
-typedef struct timeval timeit_t;
-
-void timeit_start(timeit_t * start);
-float timeit_stop(timeit_t * start);
+#include <time.h>
 
+double timeit_stop(struct timespec * start);
 
+#define timeit_start(start) clock_gettime(CLOCK_MONOTONIC, start)
 
 /*
  * Usage:
  *
- *  timeit_t start;
+ *  struct timespec start;
  *  timeit_start(&start);
  *
  *  ... some code ....
index 2c56cf0cf7b80207e3bde56e74e8915dd9105839..970e0b77075b49882ab28954817b4933d5842d37 100644 (file)
@@ -59,6 +59,25 @@ static int SIRIDB_from_unpacker(
     *siridb = NULL;                         \
     return -1;
 
+/*
+ * Returns the up-time in seconds.
+ */
+int32_t siridb_get_uptime(siridb_t * siridb)
+{
+    return (int32_t) (time(NULL) - siridb->start_ts);
+}
+
+/*
+ * Returns a value in the range 0 and 100 representing how much percent sine
+ * up-time is idle time.
+ */
+int8_t siridb_get_idle_percentage(siridb_t * siridb)
+{
+    double uptime = (double) siridb_get_uptime(siridb);
+    return (int8_t) round(siridb->tasks.idle_time / uptime * 100.0f);
+}
+
+
 /*
  * Check if at least database.conf and database.dat exist in the path.
  */
@@ -337,6 +356,9 @@ siridb_t * siridb_new(const char * dbpath, int lock_flags)
     /* start groups update thread */
     siridb_groups_start(siridb->groups);
 
+    /* start tasks */
+    siridb_tasks_init(&siridb->tasks);
+
     log_info("Finished loading database: '%s'", siridb->dbname);
 
     return siridb;
@@ -813,7 +835,6 @@ static siridb_t * SIRIDB_new(void)
                         siridb->dbname = NULL;
                         siridb->dbpath = NULL;
                         siridb->ref = 1;
-                        siridb->active_tasks = 0;
                         siridb->insert_tasks = 0;
                         siridb->flags = 0;
                         siridb->buffer_path = NULL;
index fb364dc9e57a8f9f5388a8454ff3ecf8c9375b2a..b8c8ffdd8577642cc12ec57709eac002f3e5b67c 100644 (file)
@@ -186,7 +186,7 @@ void siridb_initsync_run(uv_timer_t * timer)
             timer,
             (siridb->replicate->initsync->pkg == NULL) ?
                     INITSYNC_work : INITSYNC_send,
-            INITSYNC_SLEEP * siridb->active_tasks,
+            INITSYNC_SLEEP * siridb->tasks.active,
             0);
 }
 
index d6d18710d7d06c593da67fea7720b4cc4939ca65..8aead5440145cc2ea2a61ae6a970ab24dc9936c1 100644 (file)
@@ -26,6 +26,7 @@
 #include <siri/siri.h>
 #include <stdio.h>
 #include <string.h>
+#include <siri/db/tasks.h>
 
 #define MAX_INSERT_MSG 236
 #define INSERT_TIMEOUT 300000  // 5 minutes
@@ -349,7 +350,7 @@ int insert_init_backend_local(
     qp_next(&ilocal->unpacker, NULL); // map
     qp_next(&ilocal->unpacker, &ilocal->qp_series_name); // first series or end
 
-    siridb->active_tasks++;
+    siridb_tasks_inc(siridb->tasks);
     siridb->insert_tasks++;
 
     uv_async_init(siri.loop, handle, INSERT_local_task);
@@ -477,7 +478,7 @@ static void INSERT_local_free_cb(uv_async_t * handle)
 
     ilocal->promise->cb(ilocal->promise, NULL, ilocal->status);
 
-    ilocal->siridb->active_tasks--;
+    siridb_tasks_dec(ilocal->siridb->tasks);
     ilocal->siridb->insert_tasks--;
     if (ilocal->pcache != NULL)
     {
@@ -1057,8 +1058,9 @@ static int INSERT_init_local(
     qp_next(&ilocal->unpacker, NULL); // map
     qp_next(&ilocal->unpacker, &ilocal->qp_series_name); // first series or end
 
-    siridb->active_tasks++;
+    siridb_tasks_inc(siridb->tasks);
     siridb->insert_tasks++;
+
     uv_async_init(siri.loop, handle, INSERT_local_task);
     uv_async_send(handle);
 
index d3ae6885a53d87f89c364821e5dc780521027ad2..0d564e35664d7fffa7f2af92d3051f1207b096dd 100644 (file)
@@ -38,6 +38,10 @@ static void prop_active_handles(
         siridb_t * siridb,
         qp_packer_t * packer,
         int map);
+static void prop_active_tasks(
+        siridb_t * siridb,
+        qp_packer_t * packer,
+        int map);
 static void prop_buffer_path(
         siridb_t * siridb,
         qp_packer_t * packer,
@@ -70,6 +74,14 @@ static void prop_fifo_files(
         siridb_t * siridb,
         qp_packer_t * packer,
         int map);
+static void prop_idle_percentage(
+        siridb_t * siridb,
+        qp_packer_t * packer,
+        int map);
+static void prop_idle_time(
+        siridb_t * siridb,
+        qp_packer_t * packer,
+        int map);
 static void prop_ip_support(
         siridb_t * siridb,
         qp_packer_t * packer,
@@ -168,6 +180,8 @@ void siridb_init_props(void)
 
     siridb_props[CLERI_GID_K_ACTIVE_HANDLES - KW_OFFSET] =
             prop_active_handles;
+    siridb_props[CLERI_GID_K_ACTIVE_TASKS - KW_OFFSET] =
+            prop_active_tasks;
     siridb_props[CLERI_GID_K_BUFFER_PATH - KW_OFFSET] =
             prop_buffer_path;
     siridb_props[CLERI_GID_K_BUFFER_SIZE - KW_OFFSET] =
@@ -184,6 +198,10 @@ void siridb_init_props(void)
             prop_duration_num;
     siridb_props[CLERI_GID_K_FIFO_FILES - KW_OFFSET] =
             prop_fifo_files;
+    siridb_props[CLERI_GID_K_IDLE_PERCENTAGE - KW_OFFSET] =
+            prop_idle_percentage;
+    siridb_props[CLERI_GID_K_IDLE_TIME - KW_OFFSET] =
+            prop_idle_time;
     siridb_props[CLERI_GID_K_IP_SUPPORT - KW_OFFSET] =
             prop_ip_support;
     siridb_props[CLERI_GID_K_LIBUV - KW_OFFSET] =
@@ -239,6 +257,15 @@ static void prop_active_handles(
     qp_add_int32(packer, (int32_t) siri.loop->active_handles);
 }
 
+static void prop_active_tasks(
+        siridb_t * siridb,
+        qp_packer_t * packer,
+        int map)
+{
+    SIRIDB_PROP_MAP("active_tasks", 12)
+    qp_add_int32(packer, (int32_t) siridb->tasks.active);
+}
+
 static void prop_buffer_path(
         siridb_t * siridb,
         qp_packer_t * packer,
@@ -311,6 +338,24 @@ static void prop_fifo_files(
     qp_add_int32(packer, (int32_t) siridb_fifo_size(siridb->fifo));
 }
 
+static void prop_idle_percentage(
+        siridb_t * siridb,
+        qp_packer_t * packer,
+        int map)
+{
+    SIRIDB_PROP_MAP("idle_percentage", 15)
+    qp_add_int8(packer, siridb_get_idle_percentage(siridb));
+}
+
+static void prop_idle_time(
+        siridb_t * siridb,
+        qp_packer_t * packer,
+        int map)
+{
+    SIRIDB_PROP_MAP("idle_time", 9)
+    qp_add_int32(packer, (int32_t) siridb->tasks.idle_time);
+}
+
 static void prop_ip_support(
         siridb_t * siridb __attribute__((unused)),
         qp_packer_t * packer,
@@ -487,7 +532,7 @@ static void prop_uptime(
         int map)
 {
     SIRIDB_PROP_MAP("uptime", 6)
-    qp_add_int32(packer, (int32_t) (time(NULL) - siridb->start_ts));
+    qp_add_int32(packer, siridb_get_uptime(siridb));
 }
 
 static void prop_uuid(
index a50311adeed65dbe8d15cf18f282396c439c6690..fe5f1428743045317e1c5182643d6e6324b0b3bc 100644 (file)
@@ -70,6 +70,7 @@ void siridb_query_run(
         float factor,
         int flags)
 {
+    siridb_t * siridb;
     uv_async_t * handle = (uv_async_t *) malloc(sizeof(uv_async_t));
     if (handle == NULL)
     {
@@ -132,7 +133,8 @@ void siridb_query_run(
     }
 
     /* increment active tasks */
-    ((sirinet_socket_t *) query->client->data)->siridb->active_tasks++;
+    siridb = ((sirinet_socket_t *) query->client->data)->siridb;
+    siridb_tasks_inc(siridb->tasks);
 
     /* send next call */
     uv_async_init(siri.loop, handle, (uv_async_cb) QUERY_parse);
@@ -143,9 +145,10 @@ void siridb_query_run(
 void siridb_query_free(uv_handle_t * handle)
 {
     siridb_query_t * query = (siridb_query_t *) handle->data;
+    siridb_t * siridb = ((sirinet_socket_t *) query->client->data)->siridb;
 
     /* decrement active tasks */
-    ((sirinet_socket_t *) query->client->data)->siridb->active_tasks--;
+    siridb_tasks_dec(siridb->tasks);
 
     /* free query */
     free(query->q);
index dcd82ed04acae887b14230b304ce55d4a26cca41..36e7d7ed58a2226f062089026bf9dd8207af3243 100644 (file)
@@ -423,7 +423,7 @@ static void REINDEX_next(siridb_t * siridb)
         uv_timer_start(
                 siridb->reindex->timer,
                 REINDEX_work,
-                REINDEX_SLEEP * siridb->active_tasks,
+                REINDEX_SLEEP * siridb->tasks.active,
                 0);
         break;
 
index 5aecf6b6fe6a20cd005fb4bc795946ab22c433c2..3495bcd73190206eb5ef84f82c6496eba8521b3e 100644 (file)
@@ -383,7 +383,7 @@ static void REPLICATE_on_repl_response(
         uv_timer_start(
                 siridb->replicate->timer,
                 REPLICATE_work,
-                REPLICATE_SLEEP * siridb->active_tasks,
+                REPLICATE_SLEEP * siridb->tasks.active,
                 0);
     }
     sirinet_promise_decref(promise);
index 3de59181d878fd31572db4594634649f27dd2afe..1150f2bd8764bd835d97e0823ecc44d7a8d0ba35 100644 (file)
@@ -1157,7 +1157,7 @@ int siridb_server_cexpr_cb(
     case CLERI_GID_K_UPTIME:
         return cexpr_int_cmp(
                 cond->operator,
-                (int64_t) (time(NULL) - wserver->siridb->start_ts),
+                (int64_t) siridb_get_uptime(wserver->siridb),
                 cond->int64);
 
     case CLERI_GID_K_ACTIVE_HANDLES:
@@ -1166,6 +1166,12 @@ int siridb_server_cexpr_cb(
                 (int64_t) siri.loop->active_handles,
                 cond->int64);
 
+    case CLERI_GID_K_ACTIVE_TASKS:
+        return cexpr_int_cmp(
+                cond->operator,
+                (int64_t) wserver->siridb->tasks.active,
+                cond->int64);
+
     case CLERI_GID_K_REINDEX_PROGRESS:
         return cexpr_str_cmp(
                 cond->operator,
index 801e3e486e33d83bd1b4c7ae757a41634d7dddd5..5eafade8e39b3469ae65b6169e53184cda495ed2 100644 (file)
@@ -1302,7 +1302,7 @@ int siridb_shard_optimize(siridb_shard_t * shard, siridb_t * siridb)
 
             /* make this sleep depending on the active_tasks
              * (50ms per active task) */
-            usleep( 50000 * siridb->active_tasks + 100 );
+            usleep( 50000 * siridb->tasks.active + 100 );
         }
 
         siridb_series_decref(series);
diff --git a/src/siri/db/tasks.c b/src/siri/db/tasks.c
new file mode 100644 (file)
index 0000000..2d0bc49
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * tasks.c - SiriDB Error.
+ *
+ * author       : Jeroen van der Heijden
+ * email        : jeroen@transceptor.technology
+ * copyright    : 2016, Transceptor Technology
+ *
+ * changes
+ *  - initial version, 31-10-2016
+ *
+ */
+#include <siri/db/tasks.h>
+#include <timeit/timeit.h>
+
+void siridb_tasks_init(siridb_tasks_t * tasks)
+{
+    tasks->active = 0;
+    tasks->idle_time = 0.0f;
+    timeit_start(&tasks->_timeit);
+}
index f7e88b223838f1e9a742f2e443ee47572e554e07..da6c574b9a3875d13c641dfb26df587c79fb082f 100644 (file)
@@ -5,7 +5,7 @@
  * should be used with the libcleri module.
  *
  * Source class: SiriGrammar
- * Created at: 2018-03-30 21:57:58
+ * Created at: 2018-05-16 16:15:46
  */
 
 #include "siri/grammar/grammar.h"
@@ -31,6 +31,7 @@ cleri_grammar_t * compile_grammar(void)
     cleri_t * r_comment = cleri_regex(CLERI_GID_R_COMMENT, "^#.*");
     cleri_t * k_access = cleri_keyword(CLERI_GID_K_ACCESS, "access", CLERI_CASE_SENSITIVE);
     cleri_t * k_active_handles = cleri_keyword(CLERI_GID_K_ACTIVE_HANDLES, "active_handles", CLERI_CASE_SENSITIVE);
+    cleri_t * k_active_tasks = cleri_keyword(CLERI_GID_K_ACTIVE_TASKS, "active_tasks", CLERI_CASE_SENSITIVE);
     cleri_t * k_address = cleri_keyword(CLERI_GID_K_ADDRESS, "address", CLERI_CASE_SENSITIVE);
     cleri_t * k_after = cleri_keyword(CLERI_GID_K_AFTER, "after", CLERI_CASE_SENSITIVE);
     cleri_t * k_all = cleri_keyword(CLERI_GID_K_ALL, "all", CLERI_CASE_SENSITIVE);
@@ -76,6 +77,8 @@ cleri_grammar_t * compile_grammar(void)
         cleri_keyword(CLERI_NONE, "help", CLERI_CASE_SENSITIVE),
         cleri_token(CLERI_NONE, "?")
     );
+    cleri_t * k_idle_percentage = cleri_keyword(CLERI_GID_K_IDLE_PERCENTAGE, "idle_percentage", CLERI_CASE_SENSITIVE);
+    cleri_t * k_idle_time = cleri_keyword(CLERI_GID_K_IDLE_TIME, "idle_time", CLERI_CASE_SENSITIVE);
     cleri_t * k_info = cleri_keyword(CLERI_GID_K_INFO, "info", CLERI_CASE_SENSITIVE);
     cleri_t * k_ignore_threshold = cleri_keyword(CLERI_GID_K_IGNORE_THRESHOLD, "ignore_threshold", CLERI_CASE_SENSITIVE);
     cleri_t * k_insert = cleri_keyword(CLERI_GID_K_INSERT, "insert", CLERI_CASE_SENSITIVE);
@@ -291,7 +294,7 @@ cleri_grammar_t * compile_grammar(void)
     cleri_t * server_columns = cleri_list(CLERI_GID_SERVER_COLUMNS, cleri_choice(
         CLERI_NONE,
         CLERI_FIRST_MATCH,
-        25,
+        28,
         k_address,
         k_buffer_path,
         k_buffer_size,
@@ -307,7 +310,10 @@ cleri_grammar_t * compile_grammar(void)
         k_startup_time,
         k_status,
         k_active_handles,
+        k_active_tasks,
         k_fifo_files,
+        k_idle_percentage,
+        k_idle_time,
         k_log_level,
         k_max_open_files,
         k_mem_usage,
@@ -522,10 +528,13 @@ cleri_grammar_t * compile_grammar(void)
                 cleri_choice(
                     CLERI_NONE,
                     CLERI_FIRST_MATCH,
-                    12,
+                    15,
                     k_active_handles,
+                    k_active_tasks,
                     k_buffer_size,
                     k_fifo_files,
+                    k_idle_percentage,
+                    k_idle_time,
                     k_port,
                     k_pool,
                     k_startup_time,
@@ -1463,8 +1472,9 @@ cleri_grammar_t * compile_grammar(void)
         cleri_list(CLERI_NONE, cleri_choice(
             CLERI_NONE,
             CLERI_FIRST_MATCH,
-            31,
+            34,
             k_active_handles,
+            k_active_tasks,
             k_buffer_path,
             k_buffer_size,
             k_dbname,
@@ -1473,6 +1483,8 @@ cleri_grammar_t * compile_grammar(void)
             k_duration_log,
             k_duration_num,
             k_fifo_files,
+            k_idle_percentage,
+            k_idle_time,
             k_ip_support,
             k_libuv,
             k_list_limit,
@@ -1498,53 +1510,51 @@ cleri_grammar_t * compile_grammar(void)
         ), cleri_token(CLERI_NONE, ","), 0, 0, 0)
     );
     cleri_t * timeit_stmt = cleri_dup(CLERI_GID_TIMEIT_STMT, k_timeit);
-    cleri_t * help_select = cleri_keyword(CLERI_GID_HELP_SELECT, "select", CLERI_CASE_SENSITIVE);
-    cleri_t * help_list_groups = cleri_keyword(CLERI_GID_HELP_LIST_GROUPS, "groups", CLERI_CASE_SENSITIVE);
-    cleri_t * help_list_pools = cleri_keyword(CLERI_GID_HELP_LIST_POOLS, "pools", CLERI_CASE_SENSITIVE);
-    cleri_t * help_list_shards = cleri_keyword(CLERI_GID_HELP_LIST_SHARDS, "shards", CLERI_CASE_SENSITIVE);
-    cleri_t * help_list_users = cleri_keyword(CLERI_GID_HELP_LIST_USERS, "users", CLERI_CASE_SENSITIVE);
-    cleri_t * help_list_servers = cleri_keyword(CLERI_GID_HELP_LIST_SERVERS, "servers", CLERI_CASE_SENSITIVE);
-    cleri_t * help_list_series = cleri_keyword(CLERI_GID_HELP_LIST_SERIES, "series", CLERI_CASE_SENSITIVE);
-    cleri_t * help_list = cleri_sequence(
-        CLERI_GID_HELP_LIST,
+    cleri_t * help_access = cleri_keyword(CLERI_GID_HELP_ACCESS, "access", CLERI_CASE_SENSITIVE);
+    cleri_t * help_alter_database = cleri_keyword(CLERI_GID_HELP_ALTER_DATABASE, "database", CLERI_CASE_SENSITIVE);
+    cleri_t * help_alter_group = cleri_keyword(CLERI_GID_HELP_ALTER_GROUP, "group", CLERI_CASE_SENSITIVE);
+    cleri_t * help_alter_server = cleri_keyword(CLERI_GID_HELP_ALTER_SERVER, "server", CLERI_CASE_SENSITIVE);
+    cleri_t * help_alter_servers = cleri_keyword(CLERI_GID_HELP_ALTER_SERVERS, "servers", CLERI_CASE_SENSITIVE);
+    cleri_t * help_alter_user = cleri_keyword(CLERI_GID_HELP_ALTER_USER, "user", CLERI_CASE_SENSITIVE);
+    cleri_t * help_alter = cleri_sequence(
+        CLERI_GID_HELP_ALTER,
         2,
-        k_list,
+        k_alter,
         cleri_optional(CLERI_NONE, cleri_choice(
             CLERI_NONE,
             CLERI_MOST_GREEDY,
-            6,
-            help_list_groups,
-            help_list_pools,
-            help_list_shards,
-            help_list_users,
-            help_list_servers,
-            help_list_series
+            5,
+            help_alter_database,
+            help_alter_group,
+            help_alter_server,
+            help_alter_servers,
+            help_alter_user
         ))
     );
-    cleri_t * help_access = cleri_keyword(CLERI_GID_HELP_ACCESS, "access", CLERI_CASE_SENSITIVE);
-    cleri_t * help_revoke = cleri_keyword(CLERI_GID_HELP_REVOKE, "revoke", CLERI_CASE_SENSITIVE);
-    cleri_t * help_drop_group = cleri_keyword(CLERI_GID_HELP_DROP_GROUP, "group", CLERI_CASE_SENSITIVE);
-    cleri_t * help_drop_series = cleri_keyword(CLERI_GID_HELP_DROP_SERIES, "series", CLERI_CASE_SENSITIVE);
-    cleri_t * help_drop_user = cleri_keyword(CLERI_GID_HELP_DROP_USER, "user", CLERI_CASE_SENSITIVE);
-    cleri_t * help_drop_server = cleri_keyword(CLERI_GID_HELP_DROP_SERVER, "server", CLERI_CASE_SENSITIVE);
-    cleri_t * help_drop_shards = cleri_keyword(CLERI_GID_HELP_DROP_SHARDS, "shards", CLERI_CASE_SENSITIVE);
-    cleri_t * help_drop = cleri_sequence(
-        CLERI_GID_HELP_DROP,
+    cleri_t * help_count_groups = cleri_keyword(CLERI_GID_HELP_COUNT_GROUPS, "groups", CLERI_CASE_SENSITIVE);
+    cleri_t * help_count_pools = cleri_keyword(CLERI_GID_HELP_COUNT_POOLS, "pools", CLERI_CASE_SENSITIVE);
+    cleri_t * help_count_series = cleri_keyword(CLERI_GID_HELP_COUNT_SERIES, "series", CLERI_CASE_SENSITIVE);
+    cleri_t * help_count_servers = cleri_keyword(CLERI_GID_HELP_COUNT_SERVERS, "servers", CLERI_CASE_SENSITIVE);
+    cleri_t * help_count_shards = cleri_keyword(CLERI_GID_HELP_COUNT_SHARDS, "shards", CLERI_CASE_SENSITIVE);
+    cleri_t * help_count_users = cleri_keyword(CLERI_GID_HELP_COUNT_USERS, "users", CLERI_CASE_SENSITIVE);
+    cleri_t * help_count = cleri_sequence(
+        CLERI_GID_HELP_COUNT,
         2,
-        k_drop,
+        k_count,
         cleri_optional(CLERI_NONE, cleri_choice(
             CLERI_NONE,
             CLERI_MOST_GREEDY,
-            5,
-            help_drop_group,
-            help_drop_series,
-            help_drop_user,
-            help_drop_server,
-            help_drop_shards
+            6,
+            help_count_groups,
+            help_count_pools,
+            help_count_series,
+            help_count_servers,
+            help_count_shards,
+            help_count_users
         ))
     );
-    cleri_t * help_create_user = cleri_keyword(CLERI_GID_HELP_CREATE_USER, "user", CLERI_CASE_SENSITIVE);
     cleri_t * help_create_group = cleri_keyword(CLERI_GID_HELP_CREATE_GROUP, "group", CLERI_CASE_SENSITIVE);
+    cleri_t * help_create_user = cleri_keyword(CLERI_GID_HELP_CREATE_USER, "user", CLERI_CASE_SENSITIVE);
     cleri_t * help_create = cleri_sequence(
         CLERI_GID_HELP_CREATE,
         2,
@@ -1553,58 +1563,60 @@ cleri_grammar_t * compile_grammar(void)
             CLERI_NONE,
             CLERI_MOST_GREEDY,
             2,
-            help_create_user,
-            help_create_group
+            help_create_group,
+            help_create_user
         ))
     );
-    cleri_t * help_count_groups = cleri_keyword(CLERI_GID_HELP_COUNT_GROUPS, "groups", CLERI_CASE_SENSITIVE);
-    cleri_t * help_count_pools = cleri_keyword(CLERI_GID_HELP_COUNT_POOLS, "pools", CLERI_CASE_SENSITIVE);
-    cleri_t * help_count_shards = cleri_keyword(CLERI_GID_HELP_COUNT_SHARDS, "shards", CLERI_CASE_SENSITIVE);
-    cleri_t * help_count_users = cleri_keyword(CLERI_GID_HELP_COUNT_USERS, "users", CLERI_CASE_SENSITIVE);
-    cleri_t * help_count_servers = cleri_keyword(CLERI_GID_HELP_COUNT_SERVERS, "servers", CLERI_CASE_SENSITIVE);
-    cleri_t * help_count_series = cleri_keyword(CLERI_GID_HELP_COUNT_SERIES, "series", CLERI_CASE_SENSITIVE);
-    cleri_t * help_count = cleri_sequence(
-        CLERI_GID_HELP_COUNT,
+    cleri_t * help_drop_group = cleri_keyword(CLERI_GID_HELP_DROP_GROUP, "group", CLERI_CASE_SENSITIVE);
+    cleri_t * help_drop_series = cleri_keyword(CLERI_GID_HELP_DROP_SERIES, "series", CLERI_CASE_SENSITIVE);
+    cleri_t * help_drop_server = cleri_keyword(CLERI_GID_HELP_DROP_SERVER, "server", CLERI_CASE_SENSITIVE);
+    cleri_t * help_drop_shards = cleri_keyword(CLERI_GID_HELP_DROP_SHARDS, "shards", CLERI_CASE_SENSITIVE);
+    cleri_t * help_drop_user = cleri_keyword(CLERI_GID_HELP_DROP_USER, "user", CLERI_CASE_SENSITIVE);
+    cleri_t * help_drop = cleri_sequence(
+        CLERI_GID_HELP_DROP,
         2,
-        k_count,
+        k_drop,
         cleri_optional(CLERI_NONE, cleri_choice(
             CLERI_NONE,
             CLERI_MOST_GREEDY,
-            6,
-            help_count_groups,
-            help_count_pools,
-            help_count_shards,
-            help_count_users,
-            help_count_servers,
-            help_count_series
+            5,
+            help_drop_group,
+            help_drop_series,
+            help_drop_server,
+            help_drop_shards,
+            help_drop_user
         ))
     );
-    cleri_t * help_noaccess = cleri_keyword(CLERI_GID_HELP_NOACCESS, "noaccess", CLERI_CASE_SENSITIVE);
-    cleri_t * help_alter_server = cleri_keyword(CLERI_GID_HELP_ALTER_SERVER, "server", CLERI_CASE_SENSITIVE);
-    cleri_t * help_alter_database = cleri_keyword(CLERI_GID_HELP_ALTER_DATABASE, "database", CLERI_CASE_SENSITIVE);
-    cleri_t * help_alter_group = cleri_keyword(CLERI_GID_HELP_ALTER_GROUP, "group", CLERI_CASE_SENSITIVE);
-    cleri_t * help_alter_servers = cleri_keyword(CLERI_GID_HELP_ALTER_SERVERS, "servers", CLERI_CASE_SENSITIVE);
-    cleri_t * help_alter_user = cleri_keyword(CLERI_GID_HELP_ALTER_USER, "user", CLERI_CASE_SENSITIVE);
-    cleri_t * help_alter = cleri_sequence(
-        CLERI_GID_HELP_ALTER,
+    cleri_t * help_functions = cleri_keyword(CLERI_GID_HELP_FUNCTIONS, "functions", CLERI_CASE_SENSITIVE);
+    cleri_t * help_grant = cleri_keyword(CLERI_GID_HELP_GRANT, "grant", CLERI_CASE_SENSITIVE);
+    cleri_t * help_list_groups = cleri_keyword(CLERI_GID_HELP_LIST_GROUPS, "groups", CLERI_CASE_SENSITIVE);
+    cleri_t * help_list_pools = cleri_keyword(CLERI_GID_HELP_LIST_POOLS, "pools", CLERI_CASE_SENSITIVE);
+    cleri_t * help_list_series = cleri_keyword(CLERI_GID_HELP_LIST_SERIES, "series", CLERI_CASE_SENSITIVE);
+    cleri_t * help_list_servers = cleri_keyword(CLERI_GID_HELP_LIST_SERVERS, "servers", CLERI_CASE_SENSITIVE);
+    cleri_t * help_list_shards = cleri_keyword(CLERI_GID_HELP_LIST_SHARDS, "shards", CLERI_CASE_SENSITIVE);
+    cleri_t * help_list_users = cleri_keyword(CLERI_GID_HELP_LIST_USERS, "users", CLERI_CASE_SENSITIVE);
+    cleri_t * help_list = cleri_sequence(
+        CLERI_GID_HELP_LIST,
         2,
-        k_alter,
+        k_list,
         cleri_optional(CLERI_NONE, cleri_choice(
             CLERI_NONE,
             CLERI_MOST_GREEDY,
-            5,
-            help_alter_server,
-            help_alter_database,
-            help_alter_group,
-            help_alter_servers,
-            help_alter_user
+            6,
+            help_list_groups,
+            help_list_pools,
+            help_list_series,
+            help_list_servers,
+            help_list_shards,
+            help_list_users
         ))
     );
+    cleri_t * help_noaccess = cleri_keyword(CLERI_GID_HELP_NOACCESS, "noaccess", CLERI_CASE_SENSITIVE);
+    cleri_t * help_revoke = cleri_keyword(CLERI_GID_HELP_REVOKE, "revoke", CLERI_CASE_SENSITIVE);
+    cleri_t * help_select = cleri_keyword(CLERI_GID_HELP_SELECT, "select", CLERI_CASE_SENSITIVE);
     cleri_t * help_show = cleri_keyword(CLERI_GID_HELP_SHOW, "show", CLERI_CASE_SENSITIVE);
-    cleri_t * help_timezones = cleri_keyword(CLERI_GID_HELP_TIMEZONES, "timezones", CLERI_CASE_SENSITIVE);
     cleri_t * help_timeit = cleri_keyword(CLERI_GID_HELP_TIMEIT, "timeit", CLERI_CASE_SENSITIVE);
-    cleri_t * help_grant = cleri_keyword(CLERI_GID_HELP_GRANT, "grant", CLERI_CASE_SENSITIVE);
-    cleri_t * help_functions = cleri_keyword(CLERI_GID_HELP_FUNCTIONS, "functions", CLERI_CASE_SENSITIVE);
+    cleri_t * help_timezones = cleri_keyword(CLERI_GID_HELP_TIMEZONES, "timezones", CLERI_CASE_SENSITIVE);
     cleri_t * help = cleri_sequence(
         CLERI_GID_HELP,
         2,
@@ -1613,20 +1625,20 @@ cleri_grammar_t * compile_grammar(void)
             CLERI_NONE,
             CLERI_MOST_GREEDY,
             14,
-            help_select,
-            help_list,
             help_access,
-            help_revoke,
-            help_drop,
-            help_create,
+            help_alter,
             help_count,
+            help_create,
+            help_drop,
+            help_functions,
+            help_grant,
+            help_list,
             help_noaccess,
-            help_alter,
+            help_revoke,
+            help_select,
             help_show,
-            help_timezones,
             help_timeit,
-            help_grant,
-            help_functions
+            help_timezones
         ))
     );
     cleri_t * START = cleri_sequence(
index 317f45dedff35cef1520a9dddc7c0e052802cbd3..4d6a8376c07177297d909b8213575ab8de0c7e47 100644 (file)
@@ -1017,7 +1017,7 @@ int test_strx_to_double(void)
 
 int run_tests(void)
 {
-    timeit_t start;
+    struct timespec start;
     timeit_start(&start);
     int rc = 0;
     rc += test_qpack();
@@ -1050,7 +1050,7 @@ int run_tests(void)
     rc += test_strx_to_double();
 
     printf("\nSuccessfully performed %d tests in %.3f milliseconds!\n\n",
-            rc, timeit_stop(&start));
+            rc, timeit_stop(&start) * 1000);
 
     return 0;
 }
index 073f8664727028251aa10ca29c145da7a12e4fba..86c87a17587f7d826d5b831721f9bea6b9c48821 100644 (file)
  *
  */
 #include <timeit/timeit.h>
+#include <time.h>
 
 /*
- * Usage:
- *
- *  timeit_t start;
- *  timeit_start(&start);
- *
- *  ... some code ....
- *
- *  log_debug("Time in milliseconds: %f",timeit_stop(&start));
+ * Returns time past in seconds
  */
-void timeit_start(timeit_t * start)
-{
-    gettimeofday(start, 0);
-}
-
-float timeit_stop(timeit_t * start)
+double timeit_stop(struct timespec * start)
 {
-   timeit_t end;
+    struct timespec end;
 
-   gettimeofday(&end, 0);
+    clock_gettime(CLOCK_MONOTONIC, &end);
 
-   return (end.tv_sec - start->tv_sec) * 1000.0f +
-           (end.tv_usec - start->tv_usec) / 1000.0f;
+    return (end.tv_sec - start->tv_sec) +
+            (end.tv_nsec - start->tv_nsec) / 1000000000.0f;
 }